// file: 	history.do
// purpose: create figures of chamber size and constituency size over time.

# delimit ;

use history.dta, clear;

xtset fips year;
gen pop_pctch=S10.population/L10.population;
gen size_pctch=S10.size_low/L10.size_low;

do region.do;	
label define region
	1 "Northeast"
	2 "Midwest"
	3 "South"
	4 "West";
label values region region;

gen space="";
foreach st in OR NM NV KY LA MS IN ME {;
replace space="1" if stateabv=="`st'";
};
foreach st in WY OK NC OH NY {;
replace space="2" if stateabv=="`st'";
};
foreach st in TN WI VT {;
replace space="3" if stateabv=="`st'";
};

replace space="4" if stateabv=="VA";

destring space, replace force;
replace space=.5 if space==.;

* Graph chamber size over time, Figure 1;
	
twoway line size_low year if year>1850, by(region, rows(1) note("") legend(off) )   
	subtitle(,fcolor(none) nobox) 
	xlabel(1850(50)2000, labgap(1.25) labsize(small)) 
	ylabel(, angle(0) labgap(1.25) labsize(small))  
	ytitle(Number of Seats in Lower Chamber, size(small) margin(small)) 
	xtitle({stSans:Year},size(small) margin(small)) legend(off)
	plotregion(style(none)) scheme(s1mono) lcolor(black%40) connect(L) caption("") note("") mlabsize(tiny) xsize(6) ysize(2.5) legend(off) ; 

	graph export sl-size.pdf, replace;

* Graph constituency size by state over time, Figure OA1.;	
	
gen cshouse = population/size_low;

twoway line cshouse year if year>1850, by(region, rows(1) note("") legend(off) )   
	subtitle(,fcolor(none) nobox) 
	xlabel(1850(50)2000, labgap(1.25) labsize(small)) 
	ylabel(0(100)500, angle(0) labgap(1.25) labsize(small))
	ytitle(Lower Chamber Constituency Size, size(small) margin(small)) 
	xtitle({stSans:Year},size(small) margin(small)) legend(off)
	plotregion(style(none)) scheme(s1mono) lcolor(black%40) connect(L) 
	caption("") note("") mlabsize(tiny) xsize(6) ysize(2.5) legend(off) || 
	scatter cshouse year if cshouse>60 & year==2012 & stateabv~="CO" & stateabv~="VA" & 
		stateabv~="NC"& stateabv~="WA" & stateabv~="OR" , msymbol(none) mlabel(stateabv) mlabsize(tiny) mlabpos(3) ||
	scatter cshouse year if cshouse>60 & year==2012 & (stateabv=="CO" | stateabv=="VA" | 
		stateabv=="WA" ), msymbol(none) mlabel(stateabv) mlabsize(tiny) mlabpos(2) ||
	scatter cshouse year if cshouse>60 & year==2012 & (stateabv=="NC" | 
		stateabv=="OR") , msymbol(none) mlabel(stateabv) mlabsize(tiny) mlabpos(4);

	graph export sl-cs.pdf, replace;

* Graph constituency size by three time periods, Figure 3.	;
	
graph dot  cshouse F40.cshouse F80.cshouse if year==1932, 
	over(stateabv, sort(cshouse) label(labsize(small))) ysize(5) xsize(3.5) 
	legend(label(1 "1932") label( 2 "1972") label( 3 "2012") rows(1) size(small) nobox) 
	marker(1, mcolor(gs8%40)) marker(2, mcolor(gs5%40)) marker(3, mcolor(gs2%40))
	plotregion(style(none)) graphregion(color(white)) ylabel(,labsize(small));
	
graph export cs-history.pdf, replace	;


egen mn_size_low = mean(size_low), by(year);
egen med_size_low = median(size_low), by(year);

* Generate parameter estimates of reg of 10 year pct change in chamber size ;
*		on 10 year pct change in population;
parmby "reg size_pctch pop_pctch", by(year) 
	saving(historycoef.dta, replace);

* Graph coefs and standard errors by year, Fig 2.	;
use  historycoef.dta, clear;	
twoway line estimate year if parmseq==1 & year>1825, sort lcolor(gs2) lwidth(medium) ||
	rspike min95 max95 year if parmseq==1&year>1825, 
	lpattern(solid) lcolor(gs7) lwidth(vthin) 
	xline(1929, lcolor(maroon)) xlabel(1825(20)2010, nolabel notick nogextend)
	xmlabel(1830(10)2010) ylabel( ,nogrid) yline(0, lcolor(black)) scheme(s1mono) legend(off)
	ylabel(-1 (.5)2, angle(0)labgap(1.25) labsize(small))
	xtitle({stSans:Year},size(small) margin(small))
	ytitle(Coefficient, size(small) margin(small)) 
	plotregion(style(none));
	
	graph export pop_leg.pdf, replace;

# delimit cr	
